package org.spolo.android.topic;

import java.util.ArrayList;
import java.util.List;

import org.spolo.android.nodetree.Stage;
import org.spolo.android.nodetree.Vcanvas;
import org.spolo.android.util.ContextManager;
import org.spolo.android.util.MovieClip;
import org.spolo.android.util.MyBitmapFactory;

import android.content.Context;
import android.graphics.Bitmap;

/*
 *	author:wxd 
 *	base topic
 */
public abstract class BaseTopic {
	protected Stage stage = Stage.getInstance();
	protected List<Vcanvas> list = new  ArrayList<Vcanvas>();
	// 用于判断该Topic是否已经初始化过了
	protected boolean flag = false;
//	/**
//	 * 构造方法中初始化mc
//	 */
//	public BaseTopic(){
//		init();
//	}
	
	/**
	 * 将该topic中的movieclip从场景树中移除
	 */
	public void Deactive(){
		for(int i=0;i<list.size();i++){
			if(list.get(i) != null){
				stage.removeChild(list.get(i));
			}
			
		}
	}
	
	/**
	 * 激活该topic，将其中的movieclip添加到场景树中
	 */
	public void Active(){
		this.goInit();
		for(int i=0;i<list.size();i++){
			if(list.get(i) != null){
				stage.addChild(list.get(i));
			}
			
		}
	}
	
	/**
	 * 添加movieclip
	 * @param mc
	 */
	protected void addMc(MovieClip mc){
		this.list.add(mc);
	}
	
	/**
	 * 初始化movieclip
	 */
	protected abstract void init();
	
	/**
	 * 根据文件夹名称获取图片组
	 * @param folder 文件夹名称
	 * @return
	 */
	protected Bitmap[] getBitmaps(String folder){
		Context cont = ContextManager.getInstance().getContext("Androidshow");
		MyBitmapFactory factory = MyBitmapFactory.getInstance(cont);
		return factory.getBitmaps(folder);
	}
	
	private void goInit(){
		if(!flag){
			init();
			flag = true;
		}
	}
}
